home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 30
/
Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso
/
Aminet
/
dev
/
cross
/
GBDK-2.0.lha
/
GBDK
/
lib
/
free.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-10-01
|
578b
|
28 lines
#include <sys/malloc.h>
BYTE free( void *ptr)
{
/* Do a relativly safe free by only freeing vaild used hunks */
pmmalloc_hunk thisHunk;
thisHunk = malloc_first;
ptr = (void *)((UWORD)ptr - sizeof(mmalloc_hunk));
while (thisHunk && (thisHunk->magic==MALLOC_MAGIC)) {
if (thisHunk == ptr) {
debug("free", "Found hunk");
if (thisHunk->status == MALLOC_USED) {
thisHunk->status = MALLOC_FREE;
return 0;
}
debug("free", "Attempt to free a free hunk");
return -1;
}
thisHunk = thisHunk->next;
};
debug("free", "No hunk found");
return -2;
}